// pages/rrdetails/rrdetails.js
import {
  request2
} from "../../utils/request2";

var util = require('../../utils/util.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 初始化页面的数据
    modalHidden:true,
    recode: {},
    handlerList:[],
    handlerIndex: '#',
    mobilePhone:'',
    breakType: '',
    isWorker: false,
    roleId:'',
    srcI:'',
    imgIndex:'',
    whichClick: '',
    username:'',
    code:'',
    devices: [],
    deviceIndex: '#',
    initiator:'',
    title: '',
    dueTime: '#',
    dueTimeStart: '',
    dueTimeEnd: '',
    description: '',
    deviceCode: '',
    position: '',
    showNewPic : false,
    startPic1: "main/uploadImgsLogo.jpg",
    startPic2: "main/uploadImgsLogo.jpg",
    startPic3: "main/uploadImgsLogo.jpg",
    endPci1: "main/uploadImgsLogo.jpg",
    endPic2: "main/uploadImgsLogo.jpg",
    endPic3: "main/uploadImgsLogo.jpg",

    id: '',
    check1By: '',
    handler: '',
    check1Time: '',
    check1Note: '',
    check2By: '',
    check2Note: '',
    note: '',
    'recode.startPic1': '',
    'recode.startPic2': '',
    'recode.startPic3': '',
    'recode.endPci1': '',
    'recode.endPic2': '',
    'recode.endPic3': '',
    content: '请尽快完成该任务!',
    taskIdFlag: '%N,c,c!.mA6R@2N[',
    receiver: '',
    createtime: '',
    updatetime: '',
    msgId: '#',
    ifHadUrge: 'false',
    msgList: {},
    filesDirectory: 'https://centos.dusin.top:8443/WorkListServer/servlet/web/util/ShowPicture?file=',
  },

  // 故障图片加载,上传方法
  uploadImgs(e) {
    let index = e.currentTarget.id
    wx.chooseMedia({
      count: 1,
      mediaType: ['image', 'video'],
      sourceType: ['album', 'camera'],
      maxDuration: 15,
      sizeType: true,
      camera: 'back',

      success: res => {
        console.log(res)
        this.setData({
          srcI: res.tempFiles[0].tempFilePath,
          imgIndex: index,
          showNewPic: true,
        })
        switch (this.data.imgIndex) {
          case '1':
            // 上传方法 ，这个name属性是最重要的属性，他对应着后端传参数的值,也就是 MultipartFile file 的file
            // var time = timeUtil.formatTime(new Date());
            let that = this;
            wx.uploadFile({
              filePath: this.data.srcI,
              name: 'img',
              url: 'https://centos.dusin.top:8443/worklist2/upload/uploadimg',
              success(res) {
                console.log(res);
                let resMes = JSON.parse(res.data);
                // const surl = getApp().globalData.serverUrl + "servlet/web/util/ShowPicture?file=main/" + resMes.data;
                const surl = "main/" + resMes.data;
                if(that.data.code != 2010){
                  that.setData({
                    startPic1: surl
                  });
                }else{
                  that.setData({
                    "recode.startPic1": surl,
                    startPic1:surl
                  });
                }
              }
            })
            break;
          case '2':
            let _that = this;
            wx.uploadFile({
              filePath: this.data.srcI,
              name: 'img',
              url: 'https://centos.dusin.top:8443/worklist2/upload/uploadimg',
              success(res) {
                console.log(res);
                let resMes = JSON.parse(res.data);
                const surl = "main/" + resMes.data;
                if(_that.data.code != 2010){
                  _that.setData({
                    startPic2: surl
                  });
                }else{
                  _that.setData({
                    "recode.startPic2": surl,
                    startPic2: surl
                  });
                }
              }
            })
            break;
          case '3':
            let __that = this;
            wx.uploadFile({
              filePath: this.data.srcI,
              name: 'img',
              url: 'https://centos.dusin.top:8443/worklist2/upload/uploadimg',
              success(res) {
                console.log(res);
                let resMes = JSON.parse(res.data);
                const surl = "main/" + resMes.data;
                if(__that.data.code != 2010){
                  __that.setData({
                    startPic3: surl
                  });
                }else{
                  __that.setData({
                    "recode.startPic3": surl,
                    startPic3: surl
                  });
                }
              }
            })
            break;
          default:
            console.log("default of switch");
        }
      },
      fail() {
        console.log("图片上传取消")
      }
    })
  },

  // 完工图片加载,上传方法
  uploadEndImgs(e) {
    let index = e.currentTarget.id
    wx.chooseMedia({
      count: 1,
      mediaType: ['image', 'video'],
      sourceType: ['album', 'camera'],
      maxDuration: 15,
      sizeType: true,
      camera: 'back',

      success: res => {
        console.log(res)
        this.setData({
          srcI: res.tempFiles[0].tempFilePath,
          imgIndex: index
        })
        switch (this.data.imgIndex) {
          case '4':
            // 上传方法 ，这个name属性是最重要的属性，他对应着后端传参数的值,也就是 MultipartFile file 的file
            // var time = timeUtil.formatTime(new Date());
            let that = this;
            wx.uploadFile({
              filePath: this.data.srcI,
              name: 'img',
              url: 'https://centos.dusin.top:8443/worklist2/upload/uploadimg',
              success(res) {
                console.log(res);
                let resMes = JSON.parse(res.data);
                // const surl = getApp().globalData.serverUrl + "servlet/web/util/ShowPicture?file=main/" + resMes.data;
                const surl = "main/" + resMes.data;
                that.setData({
                  endPci1: surl,
                  "recode.endPci1": surl
                });
              }
            })
            break;
          case '5':
            let _that = this;
            wx.uploadFile({
              filePath: this.data.srcI,
              name: 'img',
              url: 'https://centos.dusin.top:8443/worklist2/upload/uploadimg',
              success(res) {
                console.log(res);
                let resMes = JSON.parse(res.data);
                const surl = "main/" + resMes.data;
                _that.setData({
                  endPic2: surl,
                  "recode.endPic2": surl
                });
              }
            })
            break;
          case '6':
            let __that = this;
            wx.uploadFile({
              filePath: this.data.srcI,
              name: 'img',
              url: 'https://centos.dusin.top:8443/worklist2/upload/uploadimg',
              success(res) {
                console.log(res);
                let resMes = JSON.parse(res.data);
                const surl = "main/" + resMes.data;
                __that.setData({
                  endPic3: surl,
                  "recode.endPic3": surl
                });
              }
            })
            break;
          default:
            console.log("default of switch");
        }
      },
      fail() {
        console.log("图片上传取消")
      }
    })
  },
  
  // 图片预览方法
  previewImg(e){
    let index = e.currentTarget.id
    console.log("预览: "+index)
    let filesDirectory = this.data.filesDirectory 
    this.setData({
      imgIndex: index
    })
    switch (this.data.imgIndex) {
      case '1':
        if(this.data.startPic1 != 'main/uploadImgsLogo.jpg'){
          wx.previewImage({
            urls: [filesDirectory+this.data.startPic1], 
          })
        }
        break;
      case '2':
        if(this.data.startPic2 != 'main/uploadImgsLogo.jpg'){
          wx.previewImage({
            urls: [filesDirectory+this.data.startPic2], 
          })
        }
        break;
      case '3':
        if(this.data.startPic3 != 'main/uploadImgsLogo.jpg'){
          wx.previewImage({
            urls: [filesDirectory+this.data.startPic3], 
          })
        }
        break;
        case '4':
        if(this.data.endPci1 != 'main/uploadImgsLogo.jpg'){
          wx.previewImage({
            urls: [filesDirectory+this.data.endPci1], 
          })
        }
        break;
        case '5':
        if(this.data.endPic2 != 'main/uploadImgsLogo.jpg'){
          wx.previewImage({
            urls: [filesDirectory+this.data.endPic2], 
          })
        }
        break;
        case '6':
        if(this.data.endPic3 != 'main/uploadImgsLogo.jpg'){
          wx.previewImage({
            urls: [filesDirectory+this.data.endPic3], 
          })
        }
        break;
      default:
        console.log("out of switch !")
        break;
    }

  },
  // 图片重新上传
  reUploadImg(e){
    let index = e.currentTarget.id
    console.log("重新上传: "+index)
    this.setData({
      imgIndex: index
    })
    switch (this.data.imgIndex) {
      case '1':
        this.setData({
          ["recode.startPic1"]: 'main/uploadImgsLogo.jpg',
          startPic1: 'main/uploadImgsLogo.jpg'
        })
        break;
      case '2':
        this.setData({
          ["recode.startPic2"]: 'main/uploadImgsLogo.jpg',
          startPic2: 'main/uploadImgsLogo.jpg'
        })
        break;
      case '3':
        this.setData({
          ["recode.startPic3"]: 'main/uploadImgsLogo.jpg',
          startPic3: 'main/uploadImgsLogo.jpg'
        })
        break;
      case '4':
        this.setData({
          ["recode.endPci1"]: 'main/uploadImgsLogo.jpg',
          endPci1: 'main/uploadImgsLogo.jpg' 
        })
        break;
      case '5':
        this.setData({
          ["recode.endPic2"]: 'main/uploadImgsLogo.jpg',
          endPic2: 'main/uploadImgsLogo.jpg' 
        })
        break;
      case '6':
        this.setData({
          ["recode.endPic3"]: 'main/uploadImgsLogo.jpg',
          endPic3: 'main/uploadImgsLogo.jpg' 
        })
        break;
      default:
        console.log("out of switch !")
        break;
    }

  },
  
  // 处理人选择器
  bindPickerChange: function(e) {
    // console.log(e)
    this.setData({
      handlerIndex: e.detail.value,
    })
    this.setData({
      handlerIndex: e.detail.value,
      handler: this.data.handlerList[this.data.handlerIndex].name
    })
    console.log(this.data.handler)
  },

  // 截止日期选择器
  dueTimeChange: function(e) {
    console.log(e)
    this.setData({
      dueTime: e.detail.value,
    })
    console.log(this.data.dueTime)
  },

  // 设备名称选择器
  deviceNameChange: function (e) {
    // console.log(e)
    console.log(this.data.devices)
    var deviceIndex = e.detail.value 
    this.setData({ 
      position: this.data.devices[deviceIndex].position,
      deviceIndex: e.detail.value,
      deviceCode: this.data.devices[deviceIndex].code,
      // deviceName: this.data.devices[deviceIndex].name
    })
    console.log(this.data.position)
    },

  // 查看设备信息,显示出设备详细信息的卡片
  showDeviceInfo(e){
    console.log(e)
    // console.log(this.data.deviceCode)
    this.setData({
      whichClick: e.currentTarget.dataset.type
    })
    wx.navigateTo({
      url: '../../pages/reviewReport/reviewReport?whichClick='+
      this.data.whichClick+
      '&deviceCode='+this.data.deviceCode+
      '&code='+this.data.code,
    })
  },

  //表单提交
  formSubmit(e){
    // console.log(e);
    let on = e.detail.target.dataset.type;
    console.log(on);
    // 根据提交按钮不同的data-type触发不同的事件
    if (on == 1) {        // 巡查人员的保存按钮触发事件(在report.js中) save
      this.setData({
        whichClick: 1,
      });

    } else if(on == 2) {  // 巡查人员的提交按钮触发事件(在report.js中) report
      this.setData({
        whichClick: 2,
      });
    } else if(on == 3) {  // 维修人员的开始执行按钮触发事件 starting 
      this.setData({
        whichClick: 3,
      });
    } else if(on == 4) {  // 经理审核上报的提交按钮触发事件 check1
      console.log(this.data.handler)
      console.log(this.data.dueTime)
      if(this.data.handler != '' && this.data.dueTime != '#'){
        this.setData({
          whichClick: 4,
          check1Note: e.detail.value.check1Note,
        });
      }else{
        console.log("必填项未填写")
        wx.showToast({
          title: '必填项未填写',
          icon: 'error'
        })
      }
    } else if(on == 5) {  // 维修人员的维修完成按钮触发事件  endTask
      this.setData({
        whichClick: 5,
        note: e.detail.value.note
      });
    } else if(on == 6) {  // 经理第一次审核时驳回按钮触发事件 deny1 
      this.setData({
        whichClick: 6,
        check1Note: e.detail.value.check1Note
      });
      console.log("点击了第一次驳回按钮")
    } else if(on == 7) {  // 经理确认结束的提交按钮触发事件
      this.setData({
        whichClick: 7,
        check2Note: e.detail.value.check2Note,
      });
    } else if(on == 8) {  // 经理的等待执行模块中一键催促按钮触发事件
      var ifHadUrge = this.data.ifHadUrge;
      if(ifHadUrge){
        wx.showToast({
          title: '催促消息已送达',
          icon: 'error',
          duration: 1000
        })
      }else{
        this.setData({
          whichClick: 8,
        });
      }
    } else if(on == 9) {  // 巡查人员的暂存上报模块按钮触发事件
      this.setData({
        whichClick: 9,
      });
      this.setData({

      })
    } else if(on == 11){  // 经理第二次审核时驳回按钮触发事件 deny2
      this.setData({
        whichClick: 11,
        check2Note: e.detail.value.check2Note
      });
      console.log("点击了第二次驳回按钮")
    } 
    this.setData({
      initiator: e.detail.value.initiator,
      title: e.detail.value.title,
      description: e.detail.value.description,  
      information: e.detail.value,
      modalHidden:false,
    });
  },

  //模态框取消
  modalCancel(){
    let on = this.data.whichClick;
    if (on==1) {
      wx.showToast({
        title: '取消保存',
        icon: 'none'
      })
    } else if(on==2 || on==4 || on==5 || on==7 || on==9) {
      wx.showToast({
        title: '取消提交',
        icon: 'none'
      })
    } else if(on == 3) {
      wx.showToast({
        title: '取消执行',
        icon: 'none'
      })
    } else if(on == 6 || on == 11) {
      wx.showToast({
        title: '取消驳回',
        icon: 'none'
      })
    } else if(on == 8) {
      wx.showToast({
        title: '取消催促',
        icon: 'none'
      })
    }
    this.setData({
      modalHidden:true,
      whichClick: '-1'
    })
  },

  //模态框确定
  modalConfirm:function(e) {
    let on = this.data.whichClick
    if (on == 3) {
      // console.log(this.data.whichClick) 
      var msgId = this.data.msgId;
      console.log("msgId:"+msgId)
      request2({
          url: "/servlet/task/starting",
          method: "POST",
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          data: {
            id: this.data.id,
            endPci1: this.data.endPci1,
            endPic2: this.data.endPic2,
            endPic3: this.data.endPic3
          }
        })
        .then(result => {
          console.log(result);
          this.setData({

          })
        })
        .catch(err => { })

      // 若是通过打开催促消息详情页执行任务,则在点击开始执行后删除该消息
      if(msgId != '#'){
        request2({ 
          url: "/servlet/message/remove",
          method: "POST",
          data: {
            id: msgId
          } 
        })
        .then(result => { 
          this.setData({
          })
        })
        .catch(err => {})  
      }

      wx.showToast({
        title: '提交成功',
        icon: 'success',
        duration: 1500
      })
      this.setData({
        modalHidden: true
      })
    } else if(on == 4){
      // console.log(this.data.whichClick)
      request2({
        url: "/servlet/task/check1",
        method: "POST",
        header: { 'content-type': 'application/x-www-form-urlencoded' 
        },
				data: {
          id: this.data.id,
          check1By: this.data.check1By,
          handler: this.data.handler,
          check1Note: this.data.check1Note,
          dueTime: this.data.dueTime
				}
			})
			.then(result => {
        console.log(result);
        wx.showToast({
          title: '提交成功',
          icon:'success'
        })
				this.setData({

         })
			})
			.catch(err => {

			})

    } else if(on == 5){
      console.log(this.data.whichClick)
      request2({
          url: "/servlet/task/endTask",
          method: "POST",
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          data: {
            id: this.data.id,
            endPci1: this.data.endPci1,
            endPic2: this.data.endPic2,
            endPic3: this.data.endPic3,
            note: this.data.note
          }
        })
        .then(result => {
          console.log(result);
          this.setData({

          })
        })
        .catch(err => {

        })
      wx.showToast({
        title: '提交成功',
        icon: 'success',
        duration: 1500
      })
      this.setData({
        modalHidden: true
      })
    } else if(on == 6){
      console.log(this.data.whichClick)
      let id = this.data.id
      let check1Note = this.data.check1Note
      request2({
          url: "/servlet/task/deny1",
          method: "POST",
          data: {
            id: id,
            check1Note: check1Note
          }
        })
        .then(result => {
          console.log(result);
          this.setData({
          })
        })
        .catch(err => {

        })
      wx.showToast({
        title: '成功驳回',
        icon: 'success',
        duration: 1500
      })
      this.setData({
        modalHidden: true
      })
    } else if(on == 7){
      console.log(this.data.whichClick)
      request2({
          url: "/servlet/task/check2",
          method: "POST",
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          data: {
            id: this.data.id,
            check2By: this.data.check2By,
            check2Note: this.data.check2Note,
          }
        })
        .then(result => {
          console.log(result);
          this.setData({

          })
        })
        .catch(err => {

        })
      wx.showToast({
        title: '提交成功',
        icon: 'success',
        duration: 1500
      })
      this.setData({
        modalHidden: true
      })
      // 经理一键催促按钮的绑定事件
    } else if(on == 8){
      // 发送指定消息内容给当前任务处理人,发送者为当前用户,消息内容在页面data的content中指定
      let persInfo = wx.getStorageSync('persInfo');
      var sender = persInfo.name;
      var receiver = this.data.receiver;
      var content = this.data.content;
      var taskIdFlag = this.data.taskIdFlag
      var createtime = util.formatTime(new Date());
      request2({
        url: "/servlet/message/save",
        method: 'POST',
        data: {
          sender: sender,
          receiver: receiver,
          content: taskIdFlag+content,
          createtime: createtime,
        } 
      })
      .then(result => { 
        console.log(result) 
        wx.showToast({
          title: '成功',
          icon: 'success',
          duration: 1000
        })
        this.setData({
        })
      })
      .catch(err => {
        wx.showToast({
          title: '失败',
          icon: 'error',
          duration: 1000
        })
      })  
    } else if(on == 9){
        request2({
          url: "/servlet/task/report",
          method: "POST",
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          data: {
            id: this.data.id,
            title: this.data.title,
            description: this.data.description,
            startPic1: this.data.startPic1,
            startPic2: this.data.startPic2,
            startPic3: this.data.startPic3,
          }
        })
        .then(result => {
          console.log(result);
          this.setData({

          })
        })
        .catch(err => {

        })
      wx.showToast({
        title: '提交成功',
        icon: 'success',
        duration: 1500
      })

    } else if(on == 11){
      console.log(this.data.whichClick)
      let id = this.data.id
      let check2Note = this.data.check2Note
      request2({
          url: "/servlet/task/deny2",
          method: "POST",
          data: {
            id: id,
            check2Note: check2Note
          }
        })
        .then(result => {
          console.log(result);
          this.setData({

          })
        })
        .catch(err => {

        })
      wx.showToast({
        title: '成功驳回',
        icon: 'success',
        duration: 1500
      })
      this.setData({
        modalHidden: true
      })
    } 
    this.setData({
      modalHidden: true
    })
    
    //更新旧页面 ,并跳转
    var pages = getCurrentPages();
    // console.log(pages)
    var prePage = pages[pages.length - 2];
    // console.log(prePage)
    prePage.onShow(); 
    if(msgId == '#'){
      wx.navigateBack ({ 
        url: '/pages/reviewReport/reviewReport',
      })
    }else{
      wx.navigateBack ({ 
        url: '/pages/message/message',
      })
    }
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // 调用该页面的onshow()方法会刷新当前页面
    // const pages = getCurrentPages()
    // const perpage = pages[pages.length - 1]
    // perpage.onLoad(this.options)  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  
  onPullDownRefresh() {
    // this.onShow();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options)
    let persInfo = wx.getStorageSync('persInfo');
    var time = util.formatTime(new Date());
    let id = options.id
    let code = options.code
    let typeCode = options.typeCode
    let deviceCode = options.deviceCode
    // 拿到deviceInfo.whichClick的值
    let whichClick = options.whichClick
    if(options.msgId != undefined){
      console.log(options.msgId)
      this.setData({
        msgId: options.msgId
      })
    }

    this.setData({
      mobilePhone: persInfo.mobilePhone,
      roleId: persInfo.roleId,
      id: options.id,
      check1By: persInfo.name,  
      check2By: persInfo.name,  
      username: persInfo.username,
      check1Time: time,
      code: code,
      deviceCode: deviceCode,
      whichClick: whichClick,
      ifHadUrge: false,
    })

    // 如果whichClick == 0 则表示用户通过点击设备名称旁的按钮后,通过查看维修记录的方式进入了rrdetails页面
    // 此时进入rrdetails.wxml的whichClick == 0分支
    if(whichClick == 0){
      request2({
        url: "/servlet/task/query",
        data: {
          page: 1,
          rows: 99,
          id: id
        }
      })
      .then(result => { 
        console.log(result) 
        let rows = result.data.data.rows.length;
        for (var i = 0; i < rows; i++) { 
          if (result.data.data.rows[i].id == id){
            let task = result.data.data.rows[i]
            let type = result.data.data.rows[i].type
            let status = result.data.data.rows[i].status
            let startPic1 = result.data.data.rows[i].startPic1
            let startPic2 = result.data.data.rows[i].startPic2
            let startPic3 = result.data.data.rows[i].startPic3
            let endPci1 = result.data.data.rows[i].endPci1
            let endPic2 = result.data.data.rows[i].endPic2
            let endPic3 = result.data.data.rows[i].endPic3
            // console.log(task);
            // console.log(type);
            switch (type) {
              case 1001:
                this.setData({
                  breakType: "电梯故障",
                })
                break;
              case 1002:
                this.setData({
                  breakType: "消防故障",
                })
                break;
              case 1003:
                this.setData({
                  breakType: "暖通故障",
                })
                break;
              default:
                this.setData({
                  breakType: "未知故障"
                })
            }
            this.setData({
              recode: task,
              status: status,
              startPic1: startPic1,
              startPic2: startPic2,
              startPic3: startPic3,
              endPci1: endPci1,
              endPic2: endPic2,
              endPic3: endPic3
            })
          }
        }
      })
      .catch(err => {}) 
    }else{
      if(code == 1002){
        { // 设置截止日期选择器的选择范围
          let nowTime = new Date();
          let nowY = nowTime.getFullYear();
          let nowM = nowTime.getMonth() + 1;
          let nowD = nowTime.getDate();
          let dueTimeStart = nowY + "-" + (nowM < 10 ? "0" + nowM : nowM) + "-" + (nowD < 10 ? "0" + nowD : nowD);// 当前日期作为开始日期
          let dueY = nowTime.getFullYear() + 5;
          let dueTimeEnd = dueY + "-" + (nowM < 10 ? "0" + nowM : nowM) + "-" + (nowD < 10 ? "0" + nowD : nowD);// 当前日期
          this.setData({
            dueTimeStart: dueTimeStart,
            dueTimeEnd: dueTimeEnd
          })
        }

        request2({
          url: "/servlet/task/query",
          data: {
            page: 1,
            rows: 99,
            status: 1,
          }
        })
        .then(result => { 
          console.log(result) 
          let rows = result.data.data.rows.length;
          for (var i = 0; i < rows; i++) { 
            if (result.data.data.rows[i].id == id){
              let task = result.data.data.rows[i]
              let type = result.data.data.rows[i].type
              let status = result.data.data.rows[i].status
              let startPic1 = result.data.data.rows[i].startPic1
              let startPic2 = result.data.data.rows[i].startPic2
              let startPic3 = result.data.data.rows[i].startPic3
              // console.log(task);
              // console.log(type);
              switch (type) {
                case 1001:
                  this.setData({
                    breakType: "电梯故障",
                  })
                  break;
                case 1002:
                  this.setData({
                    breakType: "消防故障",
                  })
                  break;
                case 1003:
                  this.setData({
                    breakType: "暖通故障",
                  })
                  break;
                default:
                  this.setData({
                    breakType: "未知故障"
                  })
              }
              this.setData({
                recode: task,
                status: status,
                startPic1: startPic1,
                startPic2: startPic2,
                startPic3: startPic3,
              })
            }
          }
        })
        .catch(err => {})  
        // 获取处理人列表
        request2({
          url: "/servlet/user/list",
          data: {}
        })
        .then(result => {
          console.log(result) 
          this.setData({
            handlerList: result.data.rows
          })
        })
        .catch(err => {}) 
      } else if(code == 1003){
        request2({
          url: "/servlet/task/query",
          data: {
            page: 1,
            rows: 99,
            status: 4,
          }
        })
        .then(result => { 
          console.log(result) 
          let rows = result.data.data.rows.length;
          for (var i = 0; i < rows; i++) { 
            if (result.data.data.rows[i].id == id){
              let task = result.data.data.rows[i]
              let type = result.data.data.rows[i].type
              let status = result.data.data.rows[i].status
              let startPic1 = result.data.data.rows[i].startPic1
              let startPic2 = result.data.data.rows[i].startPic2
              let startPic3 = result.data.data.rows[i].startPic3
              let endPci1 = result.data.data.rows[i].endPci1
              let endPic2 = result.data.data.rows[i].endPic2
              let endPic3 = result.data.data.rows[i].endPic3
              // console.log(task);
              // console.log(type);
              switch (type) {
                case 1001:
                  this.setData({
                    breakType: "电梯故障",
                  })
                  break;
                case 1002:
                  this.setData({
                    breakType: "消防故障",
                  })
                  break;
                case 1003:
                  this.setData({
                    breakType: "暖通故障",
                  })
                  break;
                default:
                  this.setData({
                    breakType: "未知故障"
                  })
              }
              this.setData({
                recode: task,
                status: status,
                startPic1: startPic1,
                startPic2: startPic2,
                startPic3: startPic3,
                endPci1: endPci1,
                endPic2: endPic2,
                endPic3: endPic3
              })
            }
          }
        })
        .catch(err => {})  
      } else if(code == 1007){
        request2({
          url: "/servlet/task/query",
          data: {
            page: 1,
            rows: 99,
            status: 2,
            id: id
          }
        })
        .then(result => {
          console.log(result) 
          let task = result.data.data.rows[0] 
          var type = task.type
          var status = task.status
          var handler = task.handler
          var id = task.id
          var startPic1 = task.startPic1
          var startPic2 = task.startPic2
          var startPic3 = task.startPic3
          // console.log(task);
          // console.log(type);
          switch (type) {
            case 1001:
              this.setData({
                breakType: "电梯故障",
              })
              break;
            case 1002:
              this.setData({
                breakType: "消防故障",
              })
              break;
            case 1003:
              this.setData({
                breakType: "暖通故障",
              })
              break;
            default:
              this.setData({
                breakType: "未知故障"
              })
              }
              this.setData({
                recode: task,
                status: status,
                receiver: handler,
                content: id,
                startPic1: startPic1,
                startPic2: startPic2,
                startPic3: startPic3,
              })
        })
        .catch(err => {})  

        // 加载消息列表 ,用来控制一键催促按钮是否已经触发
        request2({ 
          url: "/servlet/message/query",
          data: {
            page: 1,
            rows: 99,
          } 
        })
        .then(result => { 
          let msgList = result.data.rows;
          // console.log(msgList)
          /**
           * 遍历消息列表,若content>长度>16,满足substring的条件,则进行substring,
           * substring后的content若为任务id且等于当前任务id,则设置为已经催促状态,ifHadUrge==true
           * 后期消息过多,需要性能优化可以考虑把该请求放到reviewReport的onLoad中,提前查询是否已催促
           */
          msgList.forEach(element => {
            var msgContentId = element.content;
            if(msgContentId.length > 16){
              var msgContentId = element.content.substring(16);
              if(msgContentId == id){
                this.setData({
                  ifHadUrge: true,
                })
              }else{}
            }else{}
          });
        })
        .catch(err => {})  
      } else if(code == 1015){
        request2({
          url: "/servlet/task/query",
          data: {
            page: 1,
            rows: 99,
            status: 9,
          }
        })
        .then(result => { 
          console.log(result) 
          let rows = result.data.data.rows.length;
          for (var i = 0; i < rows; i++) { 
            if (result.data.data.rows[i].id == id){
              let task = result.data.data.rows[i]
              let type = result.data.data.rows[i].type
              let status = result.data.data.rows[i].status
              let startPic1 = result.data.data.rows[i].startPic1
              let startPic2 = result.data.data.rows[i].startPic2
              let startPic3 = result.data.data.rows[i].startPic3
              let endPci1 = result.data.data.rows[i].endPci1
              let endPic2 = result.data.data.rows[i].endPic2
              let endPic3 = result.data.data.rows[i].endPic3
              // console.log(task);
              // console.log(type);
              switch (type) {
                case 1001:
                  this.setData({
                    breakType: "电梯故障",
                  })
                  break;
                case 1002:
                  this.setData({
                    breakType: "消防故障",
                  })
                  break;
                case 1003:
                  this.setData({
                    breakType: "暖通故障",
                  })
                  break;
                default:
                  this.setData({
                    breakType: "未知故障"
                  })
              }
              this.setData({
                recode: task,
                status: status,
                startPic1: startPic1,
                startPic2: startPic2,
                startPic3: startPic3,
                endPci1: endPci1,
                endPic2: endPic2,
                endPic3: endPic3
              })
            }
          }
        })
        .catch(err => {}) 
      } else if(code == 2010){
        request2({
          url: "/servlet/task/query",
          data: {
            id:id,
            page:1,
            rows:99,
            status:0
          }
        })
        .then(result => { 
          console.log(result) 
          let rows = result.data.data.rows.length;
          for (var i = 0; i < rows; i++) { 
            if (result.data.data.rows[i].id == id){
              let task = result.data.data.rows[i]
              let type = result.data.data.rows[i].type
              let status = result.data.data.rows[i].status
              let startPic1 = result.data.data.rows[i].startPic1
              let startPic2 = result.data.data.rows[i].startPic2
              let startPic3 = result.data.data.rows[i].startPic3
  
              switch (type) {
                case 1001:
                  this.setData({
                    breakType: "电梯故障",
                  })
                  break;
                case 1002:
                  this.setData({
                    breakType: "消防故障",
                  })
                  break;
                case 1003:
                  this.setData({
                    breakType: "暖通故障",
                  })
                  break;
                default:
                  this.setData({
                    breakType: "未知故障"
                  })
              }
              this.setData({
                recode: task,
                status: status,
                startPic1: startPic1,
                startPic2: startPic2,
                startPic3: startPic3,
              })
            }
          }
        })
        .catch(err => {}) 
        // 根据typecode获取设备列表
        request2({
          url: '/servlet/device/listbytype?typeCode='+this.data.typeCode,
          data: {
            typeCode: typeCode,
          }
        })
        .then(res => {
          // console.log(res)
          this.setData({
            devices: res.data.rows,
          })
          // console.log(this.data.devices)
        }) 
        .catch(err => {
  
        })
        // 获取处理人列表
        request2({
          url: "/servlet/user/list",
          data: {}
        })
        .then(result => {
          // console.log(result.data.rows) 
          this.setData({
            handlerList: result.data.rows
          })
        })
        .catch(err => {}) 
      } else if(code == 2015){
        request2({
          url: "/servlet/task/query",
          data: {
            page: 1,
            rows: 99,
            id: id
          }
        })
        .then(result => { 
          console.log(result) 
  
          let rows = result.data.data.rows.length;
          for (var i = 0; i < rows; i++) { 
            if (result.data.data.rows[i].id == id){
              let task = result.data.data.rows[i]
              let type = result.data.data.rows[i].type
              let status = result.data.data.rows[i].status
              let startPic1 = result.data.data.rows[i].startPic1
              let startPic2 = result.data.data.rows[i].startPic2
              let startPic3 = result.data.data.rows[i].startPic3
              let endPci1 = result.data.data.rows[i].endPci1
              let endPic2 = result.data.data.rows[i].endPic2
              let endPic3 = result.data.data.rows[i].endPic3
              switch (type) {
                case 1001:
                  this.setData({
                    breakType: "电梯故障",
                  })
                  break;
                case 1002:
                  this.setData({
                    breakType: "消防故障",
                  })
                  break;
                case 1003:
                  this.setData({
                    breakType: "暖通故障",
                  })
                  break;
                default:
                  this.setData({
                    breakType: "未知故障"
                  })
              }
              this.setData({
                recode: task,
                status: status,
                startPic1: startPic1,
                startPic2: startPic2,
                startPic3: startPic3,
                endPci1: endPci1,
                endPic2: endPic2,
                endPic3: endPic3
              })
            }
          }
        })
        .catch(err => {}) 
      } else if(code == 3001){
        request2({
          url: "/servlet/task/query",
          data: {
            page: 1,
            rows: 99,
            status: 2,
          }
        })
        .then(result => { 
          console.log(result) 
          let rows = result.data.data.rows.length;
          for (var i = 0; i < rows; i++) { 
            if (result.data.data.rows[i].id == id){
              let task = result.data.data.rows[i]
              let type = result.data.data.rows[i].type
              let status = result.data.data.rows[i].status
              let startPic1 = result.data.data.rows[i].startPic1
              let startPic2 = result.data.data.rows[i].startPic2
              let startPic3 = result.data.data.rows[i].startPic3
              console.log(task);
              // console.log(type);
              switch (type) {
                case 1001:
                  this.setData({
                    breakType: "电梯故障",
                  })
                  break;
                case 1002:
                  this.setData({
                    breakType: "消防故障",
                  })
                  break;
                case 1003:
                  this.setData({
                    breakType: "暖通故障",
                  })
                  break;
                default:
                  this.setData({
                    breakType: "未知故障"
                  })
              }
              this.setData({
                recode: task,
                status: status,
                startPic1: startPic1,
                startPic2: startPic2,
                startPic3: startPic3,
              })
            }
          }
        })
        .catch(err => {})  
      } else if(code == 3002){
        request2({
          url: "/servlet/task/query",
          data: {
            page: 1,
            rows: 99,
            status: 3
          }
        })
        .then(result => { 
          console.log(result) 
          let rows = result.data.data.rows.length;
          for (var i = 0; i < rows; i++) { 
            if (result.data.data.rows[i].id == id){
              let task = result.data.data.rows[i]
              let type = result.data.data.rows[i].type
              let status = result.data.data.rows[i].status
              let startPic1 = result.data.data.rows[i].startPic1
              let startPic2 = result.data.data.rows[i].startPic2
              let startPic3 = result.data.data.rows[i].startPic3
              let endPci1 = result.data.data.rows[i].endPci1 
              let endPic2 = result.data.data.rows[i].endPic2 
              let endPic3 = result.data.data.rows[i].endPic3
              // console.log(task);
              // console.log(type);
              switch (type) {
                case 1001:
                  this.setData({
                    breakType: "电梯故障",
                  })
                  break;
                case 1002:
                  this.setData({
                    breakType: "消防故障",
                  })
                  break;
                case 1003:
                  this.setData({
                    breakType: "暖通故障",
                  })
                  break;
                default:
                  this.setData({
                    breakType: "未知故障"
                  })
              }
              this.setData({
                recode: task,
                status: status,
                startPic1: startPic1,
                startPic2: startPic2,
                startPic3: startPic3,
                endPci1: endPci1,
                endPic2: endPic2,
                endPic3: endPic3
              })
            }
          }
        })
        .catch(err => {})  
      } else if(code == 3003){
        request2({
          url: "/servlet/task/query",
          data: {
            page: 1,
            rows: 99,
            status: 4,
          }
        })
        .then(result => { 
          console.log(result) 
          let rows = result.data.data.rows.length;
          for (var i = 0; i < rows; i++) { 
            if (result.data.data.rows[i].id == id){
              let task = result.data.data.rows[i]
              let type = result.data.data.rows[i].type
              let status = result.data.data.rows[i].status
              let startPic1 = result.data.data.rows[i].startPic1
              let startPic2 = result.data.data.rows[i].startPic2
              let startPic3 = result.data.data.rows[i].startPic3
              let endPci1 = result.data.data.rows[i].endPci1
              let endPic2 = result.data.data.rows[i].endPic2
              let endPic3 = result.data.data.rows[i].endPic3
              // console.log(task);
              // console.log(type);
              switch (type) {
                case 1001:
                  this.setData({
                    breakType: "电梯故障",
                  })
                  break;
                case 1002:
                  this.setData({
                    breakType: "消防故障",
                  })
                  break;
                case 1003:
                  this.setData({
                    breakType: "暖通故障",
                  })
                  break;
                default:
                  this.setData({
                    breakType: "未知故障"
                  })
              }
              this.setData({
                recode: task,
                status: status,
                startPic1: startPic1,
                startPic2: startPic2,
                startPic3: startPic3,
                endPci1: endPci1,
                endPic2: endPic2,
                endPic3: endPic3
              })
            }
          }
        })
        .catch(err => {})  
      } else if(code == 3004){
        request2({
          url: "/servlet/task/query",
          data: {
            page: 1,
            rows: 99,
            status: 9,
          }
        })
        .then(result => { 
          console.log(result) 
          let rows = result.data.data.rows.length;
          for (var i = 0; i < rows; i++) { 
            if (result.data.data.rows[i].id == id){
              let task = result.data.data.rows[i]
              let type = result.data.data.rows[i].type
              let status = result.data.data.rows[i].status
              let startPic1 = result.data.data.rows[i].startPic1
              let startPic2 = result.data.data.rows[i].startPic2
              let startPic3 = result.data.data.rows[i].startPic3
              let endPci1 = result.data.data.rows[i].endPci1
              let endPic2 = result.data.data.rows[i].endPic2
              let endPic3 = result.data.data.rows[i].endPic3
              // console.log(task);
              // console.log(type);
              switch (type) {
                case 1001:
                  this.setData({
                    breakType: "电梯故障",
                  })
                  break;
                case 1002:
                  this.setData({
                    breakType: "消防故障",
                  })
                  break;
                case 1003:
                  this.setData({
                    breakType: "暖通故障",
                  })
                  break;
                default:
                  this.setData({
                    breakType: "未知故障"
                  })
              }
              this.setData({
                recode: task,
                status: status,
                startPic1: startPic1,
                startPic2: startPic2,
                startPic3: startPic3,
                endPci1: endPci1,
                endPic2: endPic2,
                endPic3: endPic3
              })
            }
          }
        })
        .catch(err => {})  
      }
    }

  },
})